package com.wenhao.beike;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-09-03 18:36
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int i = 0;i < T;i++) {
            int length = scanner.nextInt();
            String s = scanner.next();
            LinkedList<Character> stack = new LinkedList<>();
            int count = 0;
            for (int j = 0;j < s.length();j++) {
                char c = s.charAt(j);
                if (c == ')') {
                    if (stack.size() == 0) {
                        count++;
                    } else {
                        stack.pop();
                    }
                } else {
                    stack.push(c);
                }
            }
            System.out.println(count);
        }
    }
}
